/**
 * 
 * 控制权限路由的store
 * 
 */
import { RouteRecordRaw } from "vue-router"
import { isRuleRouter, baseRouter } from "../util/isRlueRouter"
import { InjectionKey } from 'vue'
import { Store } from 'vuex'
import router from '../router/index'
const state = {
    //用户的路由权限
    ruleRouter: isRuleRouter() as Array<RouteRecordRaw>,
    ruleSign:sessionStorage.getItem('rule')|| 0,
}
const actions = {
    //vuex类型不确定
    changeRuleRouter(context: any, arg: Array<RouteRecordRaw>) {
        context.commit("CHANGERULEROUTER", arg)
    },
    changeRuleSign(context: any, arg:any) {
        console.log(arg)
        context.commit("CHANGERULESIGN", arg)
    },
}

const mutations: any = {
    CHANGERULEROUTER(state:any,listRouter: Array<RouteRecordRaw>) {
        //修改路由数组
        console.log(listRouter);
        state.ruleRouter = listRouter
    },
    CHANGERULESIGN(state:any,arg: any) {
        //修改路由数组
        state.ruleSign =arg
        sessionStorage.setItem("rule",arg)
    },
}

// 定义 injection key
export const key: InjectionKey<Store<any>> = Symbol()

export default {
    namespaces: true,
    actions,
    state,
    mutations
}